<?php

namespace Controller\Single;

abstract class Base extends \Controller\Base {

	public $categoryId;

	public function actionBefore() {
		parent::actionBefore();
	}

	public function setLevelCategories() {
		$categories = \Data\Category::instance()->getLevelCategories();
		$this->assign('categories', $categories);
	}

	public function setCategoryInfo() {
		$categoryId = $this->getCategoryId();
		$this->categoryId = $categoryId;
		$parentCategoryInfo = array();
		if ($categoryId) {
			$parentCategoryInfo = \Business\Category::instance()->getParentInfoById($categoryId);
			if (!$parentCategoryInfo) {
				$this->throwException('分类信息不存在');
			}
		}

		$this->assign('categoryId', $categoryId);
		$this->assign('parentCategoryInfo', $parentCategoryInfo);
	}

	private function getCategoryId() {
		$param = $this->getRouteParams();
		return !empty($param[0]) ? (int) $param[0] : 0;
	}
}